﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using FlickrNet;

namespace FlickrDownloadr
{
    public class PhotoViewer : PictureBox
    {
        private List<Image> _watermarks;

        public List<Image> Watermarks
        {
            get
            {
                if (_watermarks == null)
                {
                    _watermarks = new List<Image>();

                    IsCreativeCommons = true;

                    switch (License)
                    {
                        case LicenseType.AllRightsReserved:
                            Watermarks.Add(Properties.Resources.cr);
                            IsCreativeCommons = false;
                            break;
                        case LicenseType.AttributionCC:
                            Watermarks.Add(Properties.Resources.by);
                            break;
                        case LicenseType.AttributionShareAlikeCC:
                            Watermarks.Add(Properties.Resources.by);
                            Watermarks.Add(Properties.Resources.sa);
                            break;
                        case LicenseType.AttributionNoDerivsCC:
                            Watermarks.Add(Properties.Resources.by);
                            Watermarks.Add(Properties.Resources.nd);
                            break;
                        case LicenseType.AttributionNonCommercialCC:
                            Watermarks.Add(Properties.Resources.by);
                            Watermarks.Add(Properties.Resources.nc);
                            break;
                        case LicenseType.AttributionNonCommercialShareAlikeCC:
                            Watermarks.Add(Properties.Resources.by);
                            Watermarks.Add(Properties.Resources.nc);
                            Watermarks.Add(Properties.Resources.sa);
                            break;
                        case LicenseType.AttributionNonCommercialNoDerivsCC:
                            Watermarks.Add(Properties.Resources.by);
                            Watermarks.Add(Properties.Resources.nc);
                            Watermarks.Add(Properties.Resources.nd);
                            break;
                    }
                }

                return _watermarks;
            }
        }

        public bool IsCreativeCommons { get; set; }

        public LicenseType License { get; set; }

        public PhotoViewer()
        {
            
        }

        private int padding = 2;
        
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            Graphics g = pe.Graphics;

            if (IsCreativeCommons)
            {
                int leftIndex = padding;

                Rectangle rect1 = new Rectangle(padding, padding, 16, 16);
                Rectangle rect2 = new Rectangle(0, 0, 16, 16);
                g.DrawImage(Properties.Resources.cc, rect1, rect2, GraphicsUnit.Pixel);

                foreach (Image img in Watermarks)
                {
                    leftIndex += 18;
                    Rectangle rectLocation = new Rectangle(leftIndex, padding, 16, 16);
                    g.DrawImage(img, rectLocation, rect2, GraphicsUnit.Pixel);
                }
            }
            else
            {
                Rectangle rect1 = new Rectangle(7, 7, 61, 61);
                Rectangle rect2 = new Rectangle(0, 0, 61, 61);
                g.DrawImage(Watermarks[0], rect1, rect2, GraphicsUnit.Pixel);
            }
        }
    }
}
